package com.newworld.basketballfire.service.controller;

import com.newworld.basketballfire.service.delegate.NoteServiceDelegate;
import com.newworld.basketballfire.service.delegate.NoteServiceDelegate;
import com.newworld.basketballfire.service.exception.ServiceException;
import com.newworld.basketballfire.service.model.Note;
import com.newworld.basketballfire.service.model.NoteParams;
import com.newworld.basketballfire.service.model.ListResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created by George on 2019/4/21.
 * NoteService
 */
@RequestMapping(value = "/rest/note")
@Controller
public class NoteService {

    @Autowired
    private NoteServiceDelegate delegate;

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public Note addNote(@RequestBody NoteParams NoteParams) throws ServiceException {
        return delegate.addNote(NoteParams);
    }

    @RequestMapping(method = RequestMethod.PUT)
    @ResponseBody
    public Note updateNote(@RequestBody NoteParams NoteParams) throws ServiceException {
        return delegate.updateNote(NoteParams.getId(), NoteParams);
    }

    @RequestMapping(method = RequestMethod.PUT, value = "/{id}")
    @ResponseBody
    public Note updateNoteById(@PathVariable String id, @RequestBody NoteParams NoteParams) throws ServiceException {
        return delegate.updateNote(id, NoteParams);
    }

    @RequestMapping(method = RequestMethod.DELETE)
    @ResponseBody
    public void deleteNote(@RequestParam String id) throws ServiceException {
        delegate.deleteNote(id);
    }

    @RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
    @ResponseBody
    public void deleteNoteById(@PathVariable String id) throws ServiceException {
        delegate.deleteNote(id);
    }

    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public Note getNote(@RequestParam String id) throws ServiceException {
        return delegate.getNote(id);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/{id}")
    @ResponseBody
    public Note getNoteById(@PathVariable String id) throws ServiceException {
        return delegate.getNote(id);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/list")
    @ResponseBody
    public ListResult<Note> getNoteList(@RequestParam(required = false, defaultValue = "") String id,
                                        @RequestParam(required = false, defaultValue = "1") Integer pageNo,
                                        @RequestParam(required = false, defaultValue = "10") Integer pageSize) throws ServiceException {
        return delegate.getNoteList(id, pageNo, pageSize);
    }


}
